[#include "../../common/html.ftl" /]
[@html]
    [@head title="修改参数" css=["fw"] /]
    [@body]
        [@formMain ]
            <div class="fw-forms">
                 [@dataForm formId="form-config-edit" ]
                    <input id="configId" type="hidden" name="configId" value="${config.configId}" />
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-4">
                        <label class="is-required">参数名称：</label>
                        <input class="am-form-field am-radius" type="text" name="configName" value="${config.configName}" required/>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-4">
                        <label class="is-required">参数键名：</label>
                        <input class="am-form-field am-radius" type="text" name="configKey" value="${config.configKey}" required/>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-4">
                        <label class="is-required">参数键值：</label>
                        <input class="am-form-field am-radius" type="text" name="configValue" value="${config.configValue}" required/>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-6 am-u-lg-4">
                        <label class="is-required">是否系统内置：</label>
                        <select class="am-radius" name="configType" required>
                            <option value="">-- 请选择 --</option>
                            [#list dict.getType("sys_yes_no") as dict]
                                [#if dict.dictValue == config.configType ]
                                    <option value="${dict.dictValue!}" selected>${dict.dictLabel}</option>
                                [#else]
                                    <option value="${dict.dictValue!}">${dict.dictLabel}</option>
                                [/#if]
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <label>备注：</label>
                        <textarea class="am-radius" name="remark" rows="5">${config.remark}</textarea>
                    </div>
                 [/@dataForm]
            </div>
        [/@formMain]

        [@rightToolbar /]

        [@script js=["fw", "validate"] progress="false" ]
            <script type="text/javascript">
                var prefix = ctx + "osfw/system/config/config";

                $("#form-config-edit").validate({
                    rules: {
                        configName: {
                            maxlength: 100,
                        },
                        configKey: {
                            maxlength: 100,
                            remote: {
                                url: prefix + "/checkConfigKeyUnique",
                                type: "post",
                                dataType: "json",
                                data: {
                                    "configId": function() {
                                        return $("#configId").val();
                                    },
                                    "configKey": function() {
                                        return $.common.trim($("input[name='configKey']").val());
                                    },
                                },
                            }
                        },
                        configValue: {
                            maxlength: 500
                        },
                        remark: {
                            maxlength: 500
                        }
                    },
                    messages: {
                        configKey: {
                            remote: "该参数键名已经存在"
                        }
                    },
                    onkeyup: false,
                    focusCleanup: true
                });

                function submitHandler() {
                    if ($.validate.form()) {
                        $.operate.save(prefix + "/edit", $('#form-config-edit').serialize());
                    }
                }
            </script>
        [/@script]
    [/@body]
[/@html]